package de.szut.bomberman.sound;

import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;


public class GameSound {
	private static String titel;
	private static long songDuration;
	private static String pause;
	static Clip musicClip;

	public static void PlayStart() {
		try {
			AudioInputStream inputStream = null;
			inputStream = AudioSystem.getAudioInputStream(new File("adios.wav"));
			AudioFormat audioFormat = inputStream.getFormat();
			int groesse = (int) (audioFormat.getFrameSize() * inputStream
					.getFrameLength());
			byte[] sound = new byte[groesse];
			DataLine.Info info = new DataLine.Info(Clip.class, audioFormat,
					groesse);
			inputStream.read(sound, 0, groesse);
			songDuration = inputStream.getFrameLength()
					/ (long) audioFormat.getFrameRate();
			musicClip = (Clip) AudioSystem.getLine(info);
			musicClip.open(audioFormat, sound, 0, groesse);

			musicClip.start();
			if (pause == "stop") {
				musicClip.loop(Clip.LOOP_CONTINUOUSLY);
			}

			Thread.sleep(songDuration * 1000);

		} catch (InterruptedException | LineUnavailableException
				| UnsupportedAudioFileException | IOException e) {
			e.printStackTrace();
		}
	}

	public static void OptionMusic() {
		PlayStart();

	}
}